/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package IO;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JPanel;

/**
 *
 * @author Eagle
 */
public class resultWriterClass {

        JFileChooser jFileChooser1;
        JPanel panel;
        groupResultClass[] resultAll;
        int simCycle;
            //save to File, first init a stream
        BufferedWriter fo=null;
        //Open file chooser

public void writeResult(){
        int returnVal=jFileChooser1.showDialog(panel,"Save As");

        if (returnVal==jFileChooser1.APPROVE_OPTION)  try {
            fo=new BufferedWriter(new FileWriter(jFileChooser1.getSelectedFile()));
            fo.write("spl_glu1,spl_glu2,spl_glu3,spl_glu4,spl_glu5,spl_glu6,"
                    + "spl_glu7,spl_glu8,spl_glu9,spl_glu10,spl_glu11,spl_glu12,"
                    + "spl_gaba1,spl_gaba2,"
                    + "spl_gaba3,spl_gaba4,spl_gaba5,spl_gaba6,spl_"
                    + "gaba7,spl_gaba8,spl_gaba9,spl_gaba10,spl_gaba11,"
                    + "spl_gaba12,spl_"
                    + "hyb1,spl_hyb2,spl_hyb3,spl_hyb4,spl_hyb5,spl_hyb6,"
                    + "spl_hyb7,spl_hyb8,spl_hyb9,spl_hyb10,spl_hyb11"
                    + ",spl_hyb12");
            fo.write("glu1,q_glu1,q_glu2,q_glu3,q_glu4,q_glu5,q_glu6,"
                    + "spl_glu7,q_glu8,q_glu9,q_glu10,q_glu11,q_glu12,"
                    + "spl_gaba1,q_gaba2,"
                    + "spl_gaba3,q_gaba4,q_gaba5,q_gaba6,q_"
                    + "gaba7,q_gaba8,q_gaba9,q_gaba10,q_gaba11,"
                    + "spl_gaba12,q_"
                    + "hyb1,q_hyb2,q_hyb3,q_hyb4,q_hyb5,q_hyb6,"
                    + "spl_hyb7,q_hyb8,q_hyb9,q_hyb10,q_hyb11"
                    + ",q_hyb12\n");

            for (int i=0;i<simCycle;i++){

                String s="";
                for (int c1=1;c1<13;c1++){
                    s=s+resultAll[i].splitGluConn()[c1]+",";
                }

                for (int c1=1;c1<13;c1++){
                    s=s+resultAll[i].splitGabaConn()[c1]+",";
                }

                for (int c1=1;c1<13;c1++){
                    s=s+resultAll[i].splitHybConn()[c1]+",";
                }
                for (int c1=1;c1<13;c1++){
                    s=s+resultAll[i].qgluConn()[c1]+",";
                }

                for (int c1=1;c1<13;c1++){
                    s=s+resultAll[i].qgabaConn()[c1]+",";
                }

                for (int c1=1;c1<13;c1++){
                    s=s+resultAll[i].qhybConn()[c1]+",";
                }


                s=s+"\n";
                fo.write(s); //dp(Integer.toString(i));
            }
            fo.close();
        }catch (IOException e) {
            //TODO Deal with IOExceptions!!
       }
    }


       resultWriterClass(JFileChooser file, JPanel jpanel,
               groupResultClass[] rzt, int simcycle){
           jFileChooser1=file;
           panel=jpanel;
           resultAll=rzt;
           simCycle=simcycle;

       }

}
